import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import '../model/category.dart';

class ChildCategory with ChangeNotifier {
  List<BxMallSubDto> _childCategoryList = [];
  int _childIndex = 0;
  int _page = 1;
  String _categoryId = '4';
  String _subId = '';
  String _noMoreText = '';
  EasyRefreshController _easyRefreshController = EasyRefreshController();

  List<BxMallSubDto> get list => _childCategoryList;
  int get childIndex => _childIndex;
  int get page => _page;
  String get categoryId => _categoryId;
  String get subId => _subId;
  String get noMoreText => _noMoreText;
  EasyRefreshController get easyRefreshController => _easyRefreshController;

  void updateChildCategoryList(List<BxMallSubDto> list, String id) {
    print('updateChildCategoryList:$id');
    _categoryId = id;
    _childIndex = 0;
    _subId = '';
    _noMoreText = '';
    _easyRefreshController.finishLoad(noMore: false);
    BxMallSubDto allItem = BxMallSubDto();
    allItem.comments = null;
    allItem.mallCategoryId = '';
    allItem.mallSubId = '';
    allItem.mallSubName = '全部';
    _childCategoryList = [allItem];
    _childCategoryList.addAll(list);
    notifyListeners();
  }

  // 修改子类索引
  void changeChildIndex(int index, String id) {
    _childIndex = index;
    _subId = id;
    _page = 1;
    _noMoreText = '';
    _easyRefreshController.finishLoad(noMore: false);
    notifyListeners();
  }

  // 增加页数
  void addPage() {
    _page++;
    notifyListeners();
  }

  // 修改nomore提示语
  void changeNoMore(String str) {
    _noMoreText = str;
    _easyRefreshController.finishLoad(noMore: true);
    notifyListeners();
  }
}